$(function () {
    var $tbody = $('tbody');

    // 点击事件，修改用户数据
    $tbody.on('click', '.change', function () {
        var uname = prompt('请输入用户名:');
        if (uname === '' || uname === undefined || uname === null) return;
        var password = prompt('请输入密码：');
        var oldName = $(this).parent('td').parent('tr').find('td')[0].innerText;
        var oldpwd = $(this).parent('td').parent('tr').find('td')[1].innerText;
        $.ajax({
            type: "post",
            url: "manager",
            data: {
                'user': uname,
                'password': password,
                'oldName': oldName,
                'oldpwd': oldpwd
            },
            success: function (xhr) {
                console.log('修改请求提交成功！');
                location.reload();
            },
            error: function (e) {
                console.log('修改请求提交失败！', e);
                location.reload();
            }
        });
    })
    // 点击事件，删除用户数据
    $tbody.on('click', '.del', function () {
        var oldName = $(this).parent('td').parent('tr').find('td')[0].innerText;
        var oldpwd = $(this).parent('td').parent('tr').find('td')[1].innerText;
        $.ajax({
            type: "post",
            url: "del",
            data: {
                "user": oldName,
                "password": oldpwd
            },
            success: function (xhr) {
                console.log("删除请求提交成功!");
                location.reload();
            },
            error: function (e) {
                console.log('删除请求提交失败！, e');
                location.reload();
            }
        })
    })
})